<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>CMS</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/jumbotron.css" rel="stylesheet">
    <link href="css/font-awesome.min.css" rel="stylesheet">
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="js/html5shiv.min.js"></script>
    <script src="js/respond.min.js"></script>
    <![endif]-->
    <!--<link href="css/nav.css" rel="stylesheet">-->
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top"></nav>

<div>
    <div class="container">
        <ul class="nav nav-tabs">
            <li class="active"><a href="javascript:reLoad();">账户</a></li>
        </ul>
    </div>

    <div class="container">
        &nbsp;
    </div>

    <div class="container">
        <div class="panel panel-default">
            <div class="panel-heading">
            	<form id="search" class="form-inline form-all" >
	            	<div class="form-group">
		                <button type="button" class="btn btn-link" data-toggle="modal" data-target="#newModal" data-ext="add">添加账户</button>
		           		<select class="form-control" id="status" name="status">
		                    <option value="">状态</option>
		                    <option value="1" >启用</option>
		                    <option value="0" >停用</option>
		                </select>
		                <select class="form-control" id="group" name="group">
		                </select>
		                <div class="input-group">
		                <div class="input-group-addon">名称</div>
		                	<input type="text" class="form-control" id="account" name="account" placeholder="账号" value="">
		                </div>
	                </div>
	                <button type="button" class="btn btn-primary" id="btn-sub">查询</button>
                </form>
            </div>
            <div class="table-responsive">
                <table class="table table-hover table-striped">
                    <thead>
                    <tr>
                        <th>#</th>
                        <th>账户</th>
                        <th>权限分组</th>
                        <th>新增/最近访问</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody id="table-body"></tbody>
                </table>
            </div>
            <nav style="text-align: right">
                <ul class="pagination"></ul>
            </nav>
        </div>
    </div>

</div>


<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/url.min.js"></script>
<script src="js/common.js"></script>
<script language="JavaScript">
	$.post(api_cfg.domain + "group_list", "", function(data){
      	    var h = '<option value="">分组</option>';
        	data.list.forEach(function(val){
        		h += '<option value="'+val.id+'">'+val.name+'</option>';
        	});
        	$("#group").html(h);
    });
    $(function(){
        auth();
        menu("user");
        $(".container").filter(":last").after(newModal);
        var page = $.url('?page');
        var status = $.url('?status');
        var account = $.url('?account');
        var group = $.url('?group');
        var opts = {
        	"page":(page != null)?page:1,
            "count":20
        };
        if(status != "" && status!= null){
        	opts.status = status;
        }
        if(account != "" && account!= null){
        	opts.account = account;
        }
        if(group != "" && group!= null){
        	opts.group = group;
        }
        api.userList(opts);
        $('#newModal').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget);
            var ext = button.data('ext');
            var recipient = button.data('whatever');
            var title = button.data('rowid');
            var src = "";
            switch(ext)
            {
                case "edit":
                    title = "#"+title;
                    src = "user_edit.html?id="+recipient;
                    break;
                case "add":
                    title = "添加账户";
                    src = "user_edit.html";
                    break;
            }
            var modal = $(this);
            modal.find('.modal-title').text(title);
            $("#newiframe").attr("src", src);
        });
        $('#newModal').on('hide.bs.modal', function (event) {
            reLoad();
        });
        $("#btn-sub").on("click", function(){
        	var status = $("#status").val();
	        var account = $("#account").val();
	        var group = $("#group").val();
	        opts.status = status;
	        opts.account = account;
	        opts.group = group;
	        opts.page = 1;
	        api.userList(opts);
        });
    });
</script>
</body>
</html>